/**
 * Copyright (c) iwindplus Technologies Co., Ltd.2024-2030, All rights reserved.
 */

package com.iwindplus.cloud.loadbalancer;

import com.iwindplus.cloud.loadbalancer.service.CustomBlockingLoadBalancerClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自定义阻塞负载均衡客户端配置.
 *
 * @author zengdegui
 * @since 2024/09/11 20:54
 */
@Slf4j
@Configuration
public class LoadBalancerBlockConfiguration {

    /**
     * 响应式框架中，无法使用feign处理.
     *
     * @param loadBalancerClientFactory
     * @return LoadBalancerClient
     */
    @ConditionalOnProperty(prefix = "loadbalancer.block", name = "enabled", havingValue = "true")
    @Bean
    public LoadBalancerClient blockingLoadBalancerClient(LoadBalancerClientFactory loadBalancerClientFactory) {
        CustomBlockingLoadBalancerClient loadBalancerClient = new CustomBlockingLoadBalancerClient(loadBalancerClientFactory);
        log.info("LoadBalancerClient={}", loadBalancerClient);
        return loadBalancerClient;
    }
}
